package com.bjb.vr.manager.controller;

import com.bjb.vr.common.ao.ResContentAo;
import com.bjb.vr.common.ao.ResPlaycontentAo;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResContentService;
import com.bjb.vr.common.service.ResPlaycontentService;
import com.bjb.vr.common.vo.ResPlatformVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * 播放内容列表
 *
 * @author maxingchen
 * @version 1.0
 * @date 2022/3/24 4:40 下午
 */
@RestController
@RequestMapping("/api/manager/v1")
public class PlayContentController {

    @Autowired
    ResPlaycontentService playContentService;
    @Autowired
    ResContentService contentService;


    /**
     * 根据条件查询课集里面课程
     *
     * @param resPlaycontentAo
     * @return
     */
    @PostMapping("/queryPlayContent")
    public BaseResult queryPlayContent(@RequestBody ResPlaycontentAo resPlaycontentAo) {
        return playContentService.queryPlayContent(resPlaycontentAo.getPlayid());
    }

    /**
     * 删除课集里面课程
     *
     * @param playid
     * @param authorization
     * @return
     */
    @PostMapping("/removePlayContent")
    public BaseResult removePlayContent(@RequestBody Long playid, @RequestHeader String authorization) {
        boolean success = playContentService.removePlayContent(playid, authorization);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_REMOVE);
        }
        return CommonResult.Ok();
    }


    /**
     * 根据条件查询某个课程具体内容
     *
     * @param resContentAo
     * @return
     */
    @PostMapping("/queryContentInfo")
    public BaseResult<ResPlatformVo> queryContentInfo(@RequestBody ResContentAo resContentAo) throws Exception {
        Assert.notNull(resContentAo.getId(), "资源id不能为空");
        ResPlatformVo resPlatformVo = contentService.queryContentInfo(resContentAo);
        return CommonResult.Ok().setResult(resPlatformVo);
    }

}
